/*
 * VideoCapture.cpp

 *
 *  Created on: 12/11/2013
 *      Author: Administrador
 */


#include "Mytypes.h"
#include "Video_Capture.h"


 using namespace cv;
 using namespace std;

 //Values for Contrast and Brightnes
 double alpha = 2.3; 	//Contrast control [1.0 - 3.0]
 int beta = 50;		//Brightnes control [0 - 100]
 int Thresshold_min = 1;
 int Thresshold_max = Thresshold_min * 200;
 int Kernel_Size = 3;

 int Flag_Log;


 void Video_Capture(void){

	 VideoCapture cap(0);

     if (!cap.isOpened()){
             cout << "Cannot load Video!" << endl;
             Flag_Log = CAN_NOT_LOAD_IMAGE;
     }




     while(1){

     Mat frame, frame_Gray, frame_Gray_filter;
     Mat frame_Gray_filter_Edge;

     bool prueba = cap.read(frame);

     if (!prueba) //if not success, break loop
     {
                     cout << "Cannot read the frame from video file" << endl;
                     break;
     }

     //cvtColor(frame, frame_Gray, CV_RGB2GRAY );
     //Filter the image
     blur(frame, frame_Gray_filter, Size(3,3) );
     //EDGE DETECTION.

     //Filter Image
     Canny(frame_Gray_filter, frame_Gray_filter_Edge, Thresshold_min, Thresshold_max, Kernel_Size);


     namedWindow("color Video", CV_WINDOW_AUTOSIZE);
     namedWindow("Edge Detect", CV_WINDOW_AUTOSIZE);


     imshow("color Video", frame);
     imshow("Edge Detect", frame_Gray_filter_Edge);


     if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
    {
             cout << "esc key is pressed by user" << endl;
             break;

    }


     }

 }



